/*
 * Copyright (C) 2009 Kristopher T Babic
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see <http://www.gnu.org/licenses>.
 */

package edu.idp.client.draw;

import edu.idp.client.interfaces.Sizeable;
import edu.idp.shared.StoredObject;
import edu.idp.shared.utils.Convert;

import java.awt.*;

/**
 *
 * @author Kristopher T Babic
 */
public class DrawAirBrush extends Drawing implements Sizeable {

    private static final int COUNT = 10;
    public static final double RADIUS_3 = 15;
    public static final double RADIUS_2 = 10;
    public static final double RADIUS_1 = 5;

    private double radius = RADIUS_3;
    private int size = 3;

    public DrawAirBrush() {
        super();
    }

    public DrawAirBrush(Component component) {
        super(component);
    }

    public void drawCurrent(Graphics g) {

        if (g == null)
            return;

        g.setColor(getColor());

        for (int i = 0; i < COUNT; i++) {
            int x = (int) (Math.random() * radius * Math.sin(Math.random() * 360.0) + (double) curPt.x);
            int y = (int) (Math.random() * radius * Math.cos(Math.random() * 360.0) + (double) curPt.y);
            g.drawLine(x, y, x, y);
        }

    }

    public void drawEnd(Graphics g) {
    }//drawCurrent(g); }

    public void drawStart(Graphics g) {
    }//drawCurrent(g); }

    public int getType() {
        return StoredObject.AIRBRUSH;
    }//DrawType.FREEHAND; }

    public void setSize(int size) {
        this.size = size;
        if (size == 1)
            radius = RADIUS_1;
        else if (size == 2)
            radius = RADIUS_2;
        else if (size == 3)
            radius = RADIUS_3;
    }

    public int getSize() {
        return this.size;
    }

    protected Rectangle getSubBounds(int min_x, int max_x, int min_y, int max_y) {
        return new Rectangle(min_x - ((int) radius / 2 + 5), min_y - ((int) radius / 2 + 5), max_x - min_x + (int) radius + 5, max_y - min_y + (int) radius + 5);
    }

    protected String storeExtra() {
        return Convert.fromInt(getSize());
    }

    protected void restoreExtra(String S) {
//    System.out.println(S.charAt(0) +","+(int)S.charAt(1)+"->"+ Convert.toInt(S.substring(0,2)));
        setSize(Convert.toInt(S.substring(0, 2)));

    }

}
